package network.protocol;

/**
 * @author Erik
 * contains all info about a building-owner
 */
public class BuildingOwnerChangedPackage {
	private int owner;
	private int buildingIndex;

	public BuildingOwnerChangedPackage(int owner, int buildingIndex) {
		this.owner = owner;
		this.buildingIndex = buildingIndex;
	}

	/**
	 * convert a correct formated string to a BuildingOwnerChangedPackage
	 * format: owner(int) + \n + buildingIndex(int) + \n
	 * @param data
	 */
	public BuildingOwnerChangedPackage(String data) {
		int start = 0, end = 0;

		end = data.indexOf('\n', start);
		owner = Integer.parseInt(data.substring(start, end));
		start = end + 1;

		end = data.indexOf('\n', start);
		buildingIndex = Integer.parseInt(data.substring(start, end));
	}

	/**
	 * convert the BuildingOwnerChangedPackage to a correct formated string
	 * @return
	 */
	public String toPackage() {
		StringBuffer res = new StringBuffer();
		res.append(owner);
		res.append('\n');

		res.append(buildingIndex);
		res.append('\n');
		
		return res.toString();
	}
	
	public int getBuilding(){
		return buildingIndex;
	}
	
	public int getOwner(){
		return owner;
	}

}
